


//
//  MBBaseFBQCell.m
//  发布求租
//
//  Created by MB__Lee on 2018/6/7.
//  Copyright © 2018年 MB__Lee. All rights reserved.
//

#import "MBBaseFBQCell.h"

#import "MBCircleBTN.h"

@implementation MBBaseFBQCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(void)setCMModel:(MBCommonCellModel *)CMModel{
    _CMModel = CMModel;
    
}
-(void)setBTNModel:(MBCircleBTNModel *)BTNModel{
    _BTNModel = BTNModel;
}
-(void)makeStaticSelectedWithIndex:(NSInteger)index{
    
}

+(CGFloat)caculateCellHightWithBTNModel:(MBCircleBTNModel *)BTNModel{
    // 2.生成按钮
//    CGFloat margin = self.margin ? self.margin : 10;
    CGFloat margin  = 10;
    
//    CGFloat hight = self.hight ? self.hight :32;
    CGFloat hight = 32;
    
//    MBCircleBTN *tempBtn = [[MBCircleBTN alloc] initWithFrame:CGRectMake(0, 40, 0, 0)];
    CGRect tempFrame = CGRectMake(0, 40, 0, 0);
    NSLog(@"%@",BTNModel);
    for (int i = 0; i < BTNModel.btnNameMut.count; i++) {
        //计算frame
        CGFloat x = CGRectGetMaxX(tempFrame);
        x += margin;
        
        CGFloat width = [self caculateStringWidth:BTNModel.btnNameMut[i]];
        
        CGFloat allwith = x + width;
        
        CGFloat y = tempFrame.origin.y;
        
        if (allwith + margin > SCREEN_WIDTH) {
            x = margin;
            
            y =  CGRectGetMaxY(tempFrame)+ margin;
        }
        
        
        CGRect frame = CGRectMake(x, y, width, hight);
//        btn.frame =CGRectMake(x, y, width, hight);
//        [btn setTitle:BTNModel.btnNameMut[i] forState:UIControlStateNormal];
//        [btn addTarget:self action:@selector(backBTN:) forControlEvents:UIControlEventTouchUpInside];
        
//        btn.layer.cornerRadius = 0.5 *hight;
        
//        [self addSubview:btn];
        
        tempFrame = frame;
        
        
    }
    
    return CGRectGetMaxY(tempFrame) + margin;
    
}
+(CGFloat)caculateStringWidth:(NSString *)str{
    NSDictionary *attrs = @{NSFontAttributeName : MBFont(14)};
    CGSize maxSize = CGSizeMake(CGFLOAT_MAX, 32);
    return [str boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size.width+ 40;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
